<?php 
/**
 *  
 * 
 * @name contacts.php
 * @author Jerome Vigne
 */
class Contacts extends CI_Controller 
{

    /**
     * Valide le formulaire de prise de contact
     */
    public function valider()
    {
        	$this->load->helper('form');
	        $this->load->library('form_validation');
	        $this->form_validation->set_rules('name', 'Name', 'required');
			$this->form_validation->set_rules('email', 'email', 'required');
			$this->form_validation->set_rules('message', 'message', 'required');
			$this->form_validation->set_rules('subject', 'subject', 'required');
	
			if ($this->form_validation->run() == FALSE)
			{
				$data['erreur'] = 'Veuillez renseigner l\'ensemble des champs !';
				$data['info'] = null;
				$data['image'] = 'contact.jpg';
	        	$data['content'] = 'public/contact';
	        	$this->load->view('layout/build/body', $data);
			}
			else
			{
				if ($this->form_validation->valid_email($this->input->post('email')) == FALSE)
				{
					$data['erreur'] = 'Veuillez rentrer un email valide !';
					$data['info'] = null;
            		$data['image'] = 'contact.jpg';
	        		$data['content'] = 'public/contact';
	        		$this->load->view('layout/build/body', $data);
				}else 
				{
					$this->load->library('email');
		            //juniorFLST@googlegroups.com
		            $this->email->to('vignejerome@free.fr', 'Contact ILS');
		            $this->email->cc($this->input->post('email'));
		            $this->email->from($this->input->post('email'));
		            $this->email->subject('ILS - Contact');
		            
		            $message = $this->input->post('message');
		            $message = html_entity_decode($message, ENT_QUOTES,'UTF-8');
		            $this->email->message($message);
		            $this->email->send();
		            
		            redirect('contacts/send');
				}
		            
			}
        /*}*/
    }
    
    /**
     * Affiche un message confirmation l'envoi du message. 
     * 
     */
    public function send()
    {
    	$data['info'] = 'Message bien envoy&eacute;';
        $data['erreur'] = null;
        $data['image'] = 'contact.jpg';
	    $data['content'] = 'public/contact';
	    $this->load->view('layout/build/body', $data);
    }
}